import { useEffect, useState } from 'react';
import { message } from 'antd';
import { fetchPullList } from '@/services/mail';

// 从服务器刷新邮件列表
const usePullList = params => {
    const [loading, setLoading] = useState(false);
    const [resData, setResData] = useState(null);

    const fetchData = async () => {
        setLoading(true);
        const { data, code, msg } = await fetchPullList(params);
        if (code === 10000) {
            setResData(data);
        } else if (msg && msg.length > 0) {
            message.error(msg);
        }
        setLoading(false);
    };
    useEffect(() => {
        if (params) {
            fetchData();
        }
    }, [params]);
    return [loading, resData];
};

export default usePullList;
